<?php
namespace app\common\model;
use think\Request;

/**
 * 商家用户模型
 */
class StoreUser extends BaseModel
{
    protected $name = 'store_user';
	protected $append = ['wxapp'];
	
	/**
     * 小程序数量
     */
    public function getWxappAttr($value, $data)
    {
        return Wxapp::useGlobalScope(false)->where([
			'store_user_id' => $data['store_user_id']
		])->count();
    }
	/**
     * 显示性别
     */
    public function getGenderAttr($value)
    {
        $status = [0 => '未知', 1 => '男', 2 => '女'];
        return $status[$value];
    }
	
	/**
     * 推荐人
     */
    public function getRecommenderAttr($value)
    {
        if($value==0){
            return ['text' => '平台推荐', 'value' => $value];
        }else{
            return ['text' => 'ID:'.$value, 'value' => $value];
        }
    }
	
	/**
     * 获取列表
	 */
    public function getList()
    {
        // 执行查询
        return $this->useGlobalScope(false)
            ->order('store_user_id','desc')
            ->paginate(15, false, ['query' => Request::instance()->request()]);
    }

	/**
     * 获取详情信息
     */
    public static function detail($store_user_id)
    {
        return self::useGlobalScope(false)->where(['store_user_id' => $store_user_id])->find();
    }
	
	/**
     * 获取详情信息 - 跟据条件
    */
    public static function getStore($where)
    {
        return self::useGlobalScope(false)->where($where)->find();
    }
	
}
